package cn.tanglong.order.controller;

import cn.tanglong.basic.exception.MyException;
import cn.tanglong.basic.util.AjaxResult;
import cn.tanglong.order.dto.OrderDto;
import cn.tanglong.order.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 订单接口
 */

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private IOrderService orderService;

    // 订单下单
    @PostMapping("/save")
    public AjaxResult save(@RequestBody OrderDto orderDto){
        try {
            String orderNo = orderService.downOrder(orderDto);
            return AjaxResult.me().setResultObj(orderNo);
        } catch (MyException e) {
            e.printStackTrace();
            return AjaxResult.me().setMsg(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMsg("接口失败！");
        }
    }
}
